/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SetupPayloadBox.java
 *
 * Created on Jul 30, 2009, 2:07:18 AM
 */

package Falcon;

import org.jdesktop.application.Action;

/**
 *
 * @author Joe
 */
public class SetupPayloadBox extends javax.swing.JDialog {

    /** Creates new form TestStrBox */
    public SetupPayloadBox(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        settingsHandler = SettingsHandler.getInstance();
        settingsHandler.loadSettings();
        setDefaults();
        fillValues();
    }


    private void setDefaults(){
        bMassVal = settingsHandler.get("PayloadSetup_bMassVal");
        weightVal = settingsHandler.get("PayloadSetup_weightVal");
        excessLiftVal = settingsHandler.get("PayloadSetup_excessLiftVal");
        dragCoefVal = settingsHandler.get("PayloadSetup_dragCoefVal");
        callsignVal = settingsHandler.get("PayloadSetup_callsignVal");
        flightNumberVal = settingsHandler.get("PayloadSetup_flightNumberVal");
    }
    private void fillValues(){
        bMassText.setText(bMassVal);
        weightText.setText(weightVal);
        excessLiftText.setText(excessLiftVal);
        dragCoefText.setText(dragCoefVal);
        callsignText.setText(callsignVal);
        flightNumberText.setText(flightNumberVal);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        bMassText = new javax.swing.JTextField();
        bMassLabel = new javax.swing.JLabel();
        cancelButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        weightLabel = new javax.swing.JLabel();
        weightText = new javax.swing.JTextField();
        jSeparator1 = new javax.swing.JSeparator();
        excessLiftLabel = new javax.swing.JLabel();
        excessLiftText = new javax.swing.JTextField();
        dragCoefLabel = new javax.swing.JLabel();
        dragCoefText = new javax.swing.JTextField();
        jSeparator2 = new javax.swing.JSeparator();
        okButton = new javax.swing.JButton();
        callsignLabel = new javax.swing.JLabel();
        callsignText = new javax.swing.JTextField();
        jSeparator3 = new javax.swing.JSeparator();
        flightNumberLabel = new javax.swing.JLabel();
        flightNumberText = new javax.swing.JTextField();
        jSeparator4 = new javax.swing.JSeparator();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(Falcon.FalconMainApp.class).getContext().getResourceMap(SetupPayloadBox.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N
        setResizable(false);

        bMassText.setText(resourceMap.getString("bMassText.text")); // NOI18N
        bMassText.setName("bMassText"); // NOI18N

        bMassLabel.setText(resourceMap.getString("bMassLabel.text")); // NOI18N
        bMassLabel.setName("bMassLabel"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(Falcon.FalconMainApp.class).getContext().getActionMap(SetupPayloadBox.class, this);
        cancelButton.setAction(actionMap.get("cancelButton")); // NOI18N
        cancelButton.setText(resourceMap.getString("cancelButton.text")); // NOI18N
        cancelButton.setName("cancelButton"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        weightLabel.setText(resourceMap.getString("weightLabel.text")); // NOI18N
        weightLabel.setName("weightLabel"); // NOI18N

        weightText.setText(resourceMap.getString("weightText.text")); // NOI18N
        weightText.setName("weightText"); // NOI18N

        jSeparator1.setName("jSeparator1"); // NOI18N

        excessLiftLabel.setText(resourceMap.getString("excessLiftLabel.text")); // NOI18N
        excessLiftLabel.setName("excessLiftLabel"); // NOI18N

        excessLiftText.setText(resourceMap.getString("excessLiftText.text")); // NOI18N
        excessLiftText.setName("excessLiftText"); // NOI18N

        dragCoefLabel.setText(resourceMap.getString("dragCoefLabel.text")); // NOI18N
        dragCoefLabel.setName("dragCoefLabel"); // NOI18N

        dragCoefText.setText(resourceMap.getString("dragCoefText.text")); // NOI18N
        dragCoefText.setName("dragCoefText"); // NOI18N

        jSeparator2.setName("jSeparator2"); // NOI18N

        okButton.setAction(actionMap.get("okButton")); // NOI18N
        okButton.setText(resourceMap.getString("okButton.text")); // NOI18N
        okButton.setName("okButton"); // NOI18N

        callsignLabel.setText(resourceMap.getString("callsignLabel.text")); // NOI18N
        callsignLabel.setName("callsignLabel"); // NOI18N

        callsignText.setName("callsignText"); // NOI18N

        jSeparator3.setName("jSeparator3"); // NOI18N

        flightNumberLabel.setText(resourceMap.getString("flightNumberLabel.text")); // NOI18N
        flightNumberLabel.setName("flightNumberLabel"); // NOI18N

        flightNumberText.setName("flightNumberText"); // NOI18N

        jSeparator4.setName("jSeparator4"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE)
                    .addComponent(jLabel1)
                    .addComponent(bMassLabel)
                    .addComponent(weightLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(bMassText, javax.swing.GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE)
                    .addComponent(weightText, javax.swing.GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE)
                    .addComponent(excessLiftLabel)
                    .addComponent(excessLiftText, javax.swing.GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE)
                    .addComponent(dragCoefLabel)
                    .addComponent(dragCoefText, javax.swing.GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE)
                    .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE)
                    .addComponent(callsignLabel)
                    .addComponent(callsignText, javax.swing.GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE)
                    .addComponent(jSeparator3, javax.swing.GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE)
                    .addComponent(flightNumberLabel)
                    .addComponent(flightNumberText, javax.swing.GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE)
                    .addComponent(jSeparator4, javax.swing.GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(okButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cancelButton)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bMassLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bMassText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(weightLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(weightText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(excessLiftLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(excessLiftText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(dragCoefLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(dragCoefText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(callsignLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(callsignText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(flightNumberLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(flightNumberText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cancelButton)
                    .addComponent(okButton))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    @Action
    public void okButton() {
        bMassVal = bMassText.getText();
        weightVal = weightText.getText();
        excessLiftVal = excessLiftText.getText();
        dragCoefVal = dragCoefText.getText();
        callsignVal = callsignText.getText();
        flightNumberVal = flightNumberText.getText();
        FalconMainView.getInstance().updateCallsign(callsignVal);
        settingsHandler.put("PayloadSetup_bMassVal", bMassText.getText());
        settingsHandler.put("PayloadSetup_weightVal", weightText.getText());
        settingsHandler.put("PayloadSetup_excessLiftVal", excessLiftText.getText());
        settingsHandler.put("PayloadSetup_dragCoefVal", dragCoefText.getText());
        settingsHandler.put("PayloadSetup_callsignVal", callsignText.getText());
        settingsHandler.put("PayloadSetup_flightNumberVal", flightNumberText.getText());
        settingsHandler.saveSettings();
        this.setVisible(false);
    }

    @Action
    public void cancelButton() {
        bMassText.setText(bMassVal);
        weightText.setText(weightVal);
        excessLiftText.setText(excessLiftVal);
        dragCoefText.setText(dragCoefVal);
        callsignText.setText(callsignVal);
        flightNumberText.setText(flightNumberVal);
        this.setVisible(false);
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel bMassLabel;
    private javax.swing.JTextField bMassText;
    private javax.swing.JLabel callsignLabel;
    private javax.swing.JTextField callsignText;
    private javax.swing.JButton cancelButton;
    private javax.swing.JLabel dragCoefLabel;
    private javax.swing.JTextField dragCoefText;
    private javax.swing.JLabel excessLiftLabel;
    private javax.swing.JTextField excessLiftText;
    private javax.swing.JLabel flightNumberLabel;
    private javax.swing.JTextField flightNumberText;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JButton okButton;
    private javax.swing.JLabel weightLabel;
    private javax.swing.JTextField weightText;
    // End of variables declaration//GEN-END:variables


    private String bMassVal;
    private String weightVal;
    private String excessLiftVal;
    private String dragCoefVal;
    private String callsignVal;
    private String flightNumberVal;
    private SettingsHandler settingsHandler;

    public String getBMassVal(){
        return bMassVal;
    }

    public String getWeightVal(){
        return weightVal;
    }

    public String getExcessLiftVal(){
        return excessLiftVal;
    }

    public String getDragCoefVal(){
        return dragCoefVal;
    }

    public String getCallsignVal(){
        return callsignVal;
    }

    public String getFlightNumber(){
        return flightNumberVal;
    }
}
